/**
 * 
 */
package org.chungyan5.mnt.lib;

import java.util.List;
import java.util.Set;

/**
 * @author yan
 *
 */
public interface Db {

	/*
	 * input both login name and pw in Construction
	 * @param loginName db login name
	 * @param pw db login pw
	 */
	
	/**
	 * open this db
	 * @return true successfully connected, otherwise false
	 */
	public boolean open();
	
	/**
	 * close this db
	 */
	public void close();
	
	/**
	 * adding a new tag
	 * 
	 * @return a new just created tag; null as fail to create this new tag 
	 */
	public MNTTag newTag(MNTTag tag);
	
	/**
	 * query existing tag(s) in alphabetic(Capital Letter, then small letter)
	 * 
	 * @return tag(s) List in DB ordering
	 */
	public List<MNTTag> queryTags();
	
	/**
	 * find back tag by its id 
	 * @param id a known id of a tag
	 * @return a tag corresponding to that id
	 */
	public MNTTag queryTag(long id);
	
	/**
	 * modify a existing tag
	 * 
	 * @param tag a tag with new updated content
	 * @return a just updated tag
	 */
	public MNTTag updateTag(MNTTag tag);
	
	/**
	 * remove a existing tag fr. Tag Table
	 * 
	 * @param tag a tag ready to remove
	 * @return true as success to remove, false as fault to remove this tag
	 */
	public boolean removeTag(MNTTag tag);
 
	/**
	 * remove all records related to a tag from "Tags and Items many to many relation table"
	 * 
	 * @param tag this tag related record(s) to remove
	 * @return true as success to remove, false as fault to remove
	 */
	public boolean removeTagFrItemTagRel(MNTTag tag);
 
	/**
	 * adding a new item, not including tag attachment
	 * 
	 * @param item new created item
	 * @return a new just created item including its new assigned ID
	 */
	public Item newItem(Item item);
	
	/**
	 * find back Item by its id 
	 * @param id a known id of a Item
	 * @return a Item corresponding to that id
	 */
	public Item queryItem(long id);
	
	/**
	 * query existing item(s) with Item attached empty tag in alphabetic(Capital Letter, then small letter)
	 * 
	 * @return item(s) in List<Item> format as ordered collection
	 */
	public List<Item> queryItemsWithEmptyTag();
	
	/**
	 * query existing item(s) by selected tag and non-selected Tag by SQL in alphabetic(Capital Letter, then small letter)
	 * 	in case of existing of both selected tag and non-selected Tag Or
	 * 	either have selected tag or non-selected tag
	 * 	not for both null of selected tag or non-selected tag, we can call queryItemsWithEmptyTag() for this case 
	 * 
	 * @param selectedPlusTags select Tags in Set format as non-duplicated and non-ordering
	 * @param selectedNegTags non-select Tags in Set format as non-duplicated and non-ordering
	 * @return item(s) in List<Item> format as ordered collection
	 */
	public List<Item> queryItems(Set<MNTTag> selectedPlusTags, Set<MNTTag> selectedNegTags);
	
	/**
	 * modify a existing item not included attached tag(s)
	 * 
	 * @param Item a Item with new updated content
	 * @return a just updated Item
	 */
	public Item updateItem(Item item);
	
	/**
	 * remove a existing item
	 * 
	 * @param item a item ready to remove
	 * @return true as success to remove, false as fault to remove this item
	 */
	public boolean removeItem(Item item);
	
	/**
	 * remove all records related to a item from "Tags and Items many to many relation table"
	 * 
	 * @param item this item related record(s) to remove
	 * @return true as success to remove, false as fault to remove
	 */
	public boolean removeFrItemTagRel(Item item);
	
	/**
	 * insert a connect tag and item record into "Tags and Items many to many relation table"
	 * @param item item to connect to the tag
	 * @param tag tag to connect to the item
	 * @return true as connect successful, otherwise false
	 */
	public boolean connectTagItem(Item item, MNTTag tag);
 
	/**
	 * remove the tag and item record from "Tags and Items many to many relation table"
	 * @param item item to disconnect to the tag
	 * @param tag tag to disconnect to the item
	 * @return true as disconnect successful, otherwise false
	 */
	public boolean disConnectTagItem(Item item, MNTTag tag);
	
	/**
	 * query related tag(s) of specific item from "Tags and Items many to many relation table" in alphabetic(Capital Letter, then small letter)
	 * OR does item record exist at "Tags and Items many to many relation table"? if ZERO size of related tag  
	 * @param item is this item still inside matching table
	 * @return 0 as item does not existing at this matching table; >0 as item is still at there and its related tag(s)  
	 * @return tag(s) in TreeSet<Tag> format as ordered and no duplication collection
	 */
	public Set<MNTTag> queryRelTags(Item item);
	
}
